﻿using B.S.DataBase.MyProject.Domain.Infrastructures;
using B.S.DataBase.MyProject.Domain.wdx.ViewModels;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure;
using MediatR;
using MedicalPCTerminal.Read.API.Appcation.Commands.Sign;
using System.Collections.Generic;

namespace MedicalPCTerminal.Read.API.Appcation.CommandHandlers.Sign
{
    public class GetDoctorSelectCommandHandler : IRequestHandler<GetDoctorSelectCommand, APIResult<List<View_DoctorSelect>>>
    {
        private readonly SqlSugarContext sqlSugar;

        public GetDoctorSelectCommandHandler(SqlSugarContext sqlSugar)
        {
            this.sqlSugar = sqlSugar;
        }

        public Task<APIResult<List<View_DoctorSelect>>> Handle(GetDoctorSelectCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<View_DoctorSelect>> result = new APIResult<List<View_DoctorSelect>>();
            var team = sqlSugar.db.Queryable<TeamInfo>().First(x => x.TeamID == request.TeamID);
            string[] dockers = team.TeamMembers.Split(',');
            List<View_DoctorSelect> list = new List<View_DoctorSelect>();
            foreach (string docker in dockers) 
            {
                list.Add(new View_DoctorSelect()
                {
                    TeamID = team.TeamID,
                    DoctorName = docker
                });
            }
            result.data = list.ToList();
            result.Code = APIEnum.查询成功;
            result.Msg = APIEnum.查询成功.ToString();
            return Task.FromResult(result);
        }
    }
}
